<h1 id="日期时间">日期时间</h1>
<h3 id="获取当前时间毫秒值">获取当前时间毫秒值</h3>
<pre><code class="hljs language-javascript"><span class="hljs-title function_">println</span>(<span class="hljs-title function_">timestamp</span>()) <span class="hljs-comment">// 1628643356690</span>
</code></pre>
<h3 id="获取当前时间纳秒值">获取当前时间纳秒值</h3>
<pre><code class="hljs language-javascript"><span class="hljs-title function_">println</span>(<span class="hljs-title function_">nanosecond</span>()) <span class="hljs-comment">// 1628643387685050100</span>
</code></pre>
<h3 id="datetime">DateTime</h3>
<ol>
<li><p>日期格式字符串转DateTime</p>
<pre><code class="hljs language-javascript"><span class="hljs-title function_">println</span>(<span class="hljs-title function_">parseDate</span>(<span class="hljs-string">&quot;2017/05/12&quot;</span>, <span class="hljs-string">&quot;y/M/d&quot;</span>).<span class="hljs-title function_">string</span>()) <span class="hljs-comment">// 2017-05-12 00:00:00</span>
</code></pre>
</li>
<li><p>毫秒值转DateTime</p>
<pre><code class="hljs language-javascript"><span class="hljs-title function_">println</span>(<span class="hljs-title function_">newDate</span>(<span class="hljs-number">1118643356690</span>).<span class="hljs-title function_">string</span>()) <span class="hljs-comment">// 2005-06-13 14:15:56</span>
</code></pre>
</li>
<li><p>纳秒值转DateTime</p>
<pre><code class="hljs language-javascript"><span class="hljs-title function_">println</span>(<span class="hljs-title function_">newDate1</span>(<span class="hljs-number">1238643387685050123</span>).<span class="hljs-title function_">string</span>()) <span class="hljs-comment">// 2009-04-02 11:36:27</span>
</code></pre>
</li>
<li><p>当前时间的DateTime对象</p>
<pre><code class="hljs language-javascript">dt = <span class="hljs-title function_">now</span>()
<span class="hljs-comment">// 日期格式化</span>
<span class="hljs-title function_">println</span>(dt.<span class="hljs-title function_">format</span>(<span class="hljs-string">&quot;y/M/d h:m:s.S&quot;</span>)) <span class="hljs-comment">// 2021/08/11 17:02:01.837</span>
<span class="hljs-comment">// 年</span>
<span class="hljs-title function_">println</span>(dt.<span class="hljs-title function_">year</span>()) <span class="hljs-comment">// 2021</span>
<span class="hljs-comment">// 月</span>
<span class="hljs-title function_">println</span>(dt.<span class="hljs-title function_">month</span>()) <span class="hljs-comment">// 8</span>
<span class="hljs-comment">// 日</span>
<span class="hljs-title function_">println</span>(dt.<span class="hljs-title function_">day</span>()) <span class="hljs-comment">// 11</span>
<span class="hljs-comment">// 时</span>
<span class="hljs-title function_">println</span>(dt.<span class="hljs-title function_">hour</span>()) <span class="hljs-comment">// 17</span>
<span class="hljs-comment">// 分</span>
<span class="hljs-title function_">println</span>(dt.<span class="hljs-title function_">minute</span>()) <span class="hljs-comment">// 2</span>
<span class="hljs-comment">// 秒</span>
<span class="hljs-title function_">println</span>(dt.<span class="hljs-title function_">second</span>()) <span class="hljs-comment">// 1</span>
</code></pre>
</li>
</ol>
<h3 id="datetime方法">DateTime方法</h3>
<table>
<thead>
<tr>
<th>方法</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>format(fmt)</td>
<td>日期格式化， y(年), M(月), d(日), h(时), m(分), s(秒), S(毫秒)</td>
</tr>
<tr>
<td>ms()</td>
<td>毫秒值</td>
</tr>
<tr>
<td>ns()</td>
<td>纳秒值</td>
</tr>
<tr>
<td>year()</td>
<td>年</td>
</tr>
<tr>
<td>month()</td>
<td>月,[1, 12]</td>
</tr>
<tr>
<td>day()</td>
<td>日,[1, 30]</td>
</tr>
<tr>
<td>hour()</td>
<td>时,[0, 23]</td>
</tr>
<tr>
<td>minute()</td>
<td>分,[0, 59]</td>
</tr>
<tr>
<td>second()</td>
<td>秒,[0, 59]</td>
</tr>
</tbody></table>
